/**
 * 
 */
package com.base.myproject.client.busi.system;

import java.util.ArrayList;
import java.util.List;

import com.base.myproject.client.ui.celleditor.BaseGridEditor;
import com.base.myproject.client.ui.codenamemap.CodeNameMapFactory;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * 检查用户是否存在的类，
 * @author zgw
 *
 */
public abstract class BcodeChecker implements AsyncCallback<Boolean>,Listener<BaseEvent>{
	
	protected String bcode,password,extfilter;
	protected Dialog d = new Dialog();
	protected BaseGridEditor bge2;
	protected TextField<String> pass_t = new TextField<String>();
	
	protected FormPanel formpanel = new FormPanel();
	public BcodeChecker()
	{
		
	}
	public BcodeChecker(String bcode,String password)
	{
		this.bcode = bcode;
		this.password = password;
	}
	
	public String getBcode() {
		return bcode;
	}
	public void setBcode(String bcode) {
		this.bcode = bcode;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getExtfilter() {
		return extfilter;
	}
	public void setExtfilter(String extfilter) {
		this.extfilter = extfilter;
	}
	public void showDialog()
	{
		d.setWidth("100");
		CodeNameMapFactory cnmf = new CodeNameMapFactory();
		
		List<ColumnConfig> bocodecolumns2 = new ArrayList<ColumnConfig>();
		ColumnConfig bcode2 = new ColumnConfig("code", "人员", 100);

		bocodecolumns2.add(bcode2);

		ColumnConfig bname = new ColumnConfig("name", "人员名", 100);
		bocodecolumns2.add(bname);
		bge2 = new BaseGridEditor(bocodecolumns2, cnmf
				.getBasebcodestore_canChangePO(), "name", "code");
		//final TextField<String> bge2 = new TextField<String>();
		bge2.setFieldLabel("操作员");
		bge2.setAllowBlank(false);
		 //----
		
		pass_t.setAllowBlank(false);
		pass_t.setFieldLabel("密码");
		pass_t.setPassword(true);
		
		formpanel.setLabelWidth(75);
		formpanel.setFieldWidth(120);
		formpanel.add(bge2);
		formpanel.add(pass_t);
		
		d.setSize(260, 400);
		d.add(formpanel);
		d.setButtons(Dialog.OKCANCEL);
		d.getButtonById(Dialog.CANCEL).addListener(Events.Select, this);
		d.getButtonById(Dialog.OK).addListener(Events.Select, this);
		d.show();
	}
	public void checkbcode()
	{
		final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT
		.create(com.base.myproject.client.tools.GreetingService.class);
		greetingService.checkhasBcode(" bcode="+bge2.getCode()+" and password='"+pass_t.getValue()+"'"+(extfilter==null?"":" and "+extfilter),this);
	}
	
	public void handleEvent(BaseEvent be) {
		
		  if(be.getSource() == d.getButtonById(Dialog.CANCEL))
			{
				d.setVisible(false);
			}
			else if(be.getSource() == d.getButtonById(Dialog.OK))
			{
				if(formpanel.isValid())
				{
				checkbcode();
			
				}
			}
	}
	

}
